package com.kobe.util;

import java.util.LinkedList;

public class Prime {
    /**
     * 
     * 
     */
    public static boolean isPrime(int number) {
        number = number < 0 ? number * (-1) : number;
        if (number == 1){
            return false;
        }
        int sqrt = (int) Math.sqrt(number);
        boolean isPrime = true;

        if (number % 2 == 0 && number != 2) {
            isPrime = false;
        } else {
            for (int i = 3; i <= sqrt; i += 2) {
                if (number % i == 0) {
                    isPrime = false;
                    break;
                }
            }
        }
        return isPrime;
    }

    public static LinkedList<Integer> getPrimesOfTheRange(int range) {
        LinkedList<Integer> primes = new LinkedList<Integer>();
        if (range < 2) {
            return primes;
        }
        if (range == 2) {
            primes.add(2);
            return primes;
        }
        for (int i = 3; i <= range; i = i + 2) {
            if (isPrime(i)) {
                primes.add(i);
            }
        }

        return primes;
    }

    public static void main(String[] args) {
        System.out.println(isPrime(1));
        
//        for (int i = 2; i < 100; i++) {
//            if (isPrime(i)) {
//                System.out.println(i);
//            }
//        }
    }
}
